import os.path

from django.db import models
# Create your models here.
from mdeditor.fields import MDTextField
# from Main.utils import ImageStorage
from storages.backends.ftp import FTPStorage


class Motto(models.Model):
    motto_id = models.IntegerField(unique=True, blank=True, null=True)
    m_words = models.CharField(max_length=255)
    m_picture = models.CharField(max_length=255, null=True)

    class Meta:
        db_table = "motto"


class NoteMenu(models.Model):
    menu_id = models.IntegerField(unique=True, blank=True, null=True)
    menu_code = models.CharField(max_length=64, unique=True)
    menu_name = models.CharField(max_length=64)
    menu_create_time = models.DateTimeField(auto_now=True)
    menu_status = models.BooleanField(default=True)

    class Meta:
        db_table = "note_menu"


class NoteArticle(models.Model):
    article_id = models.IntegerField(unique=True, blank=True, null=True)
    menu_code = models.CharField(max_length=64, verbose_name="文章所属类型,对应note_menu表中的menu_code，如果有多个类型用空格分开")
    article_name = models.CharField(max_length=64, verbose_name="文章名称")
    article_author = models.CharField(max_length=64, verbose_name="文章作者", null=True)
    article_content = MDTextField(verbose_name="正文内容，markdown格式")
    article_create_time = models.DateTimeField(auto_now=True, verbose_name="文章创建时间")
    article_update_time = models.DateTimeField(auto_now=True, verbose_name="文章更新时间")
    article_status = models.BooleanField(default=True, verbose_name="状态,True有效，false无效")
    # linux中ftp的 /var/ftp/images 已经和nginx图片地址 /home/image/images 已经软链接
    # 前端访问封面：http://124.223.109.79/image/media/frontImages/frontimage-file-name
    # ftp 服务器 root path : /home/image/images/media
    article_image = models.ImageField(upload_to='frontImages', verbose_name="文章封面图片",
                                      storage=FTPStorage(), null=True)

    class Meta:
        db_table = "note_article"
        verbose_name = "文章内容表"


class AccessLog(models.Model):
    access_unique_id = models.AutoField(primary_key=True, verbose_name="唯一ID")
    access_ip_addr = models.CharField(max_length=128, verbose_name="访问人的IP地址")
    access_path = models.CharField(max_length=128, verbose_name="访问路径")
    access_time = models.DateTimeField(auto_now=True, verbose_name="访问时间")

    class Meta:
        db_table = "t_access_log"
        verbose_name = "用户访问记录表"


class Calender(models.Model):
    cal_date = models.CharField(db_index=True, unique=True, max_length=8, verbose_name="日历日期")
    is_break = models.NullBooleanField(default=False, verbose_name="是否为假期")
    break_type = models.IntegerField(verbose_name="假期类型，0/null：非假期，1：双休日，2：国家节假日")

    class Meta:
        db_table = "t_calender"
        verbose_name = "节假日表"
